package com.gizwits.opensource.appkit.ControlModule;

import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiDeviceListener;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;

import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.concurrent.ConcurrentHashMap;

public class GosDeviceControlActivity extends GosBaseActivity{

	/** 智能灯设备 */
	private GizWifiDevice device;
	/** 导航栏 */
	ActionBar actionBar;
	/** 在云端创建的数据点标识名 */
	public static final String SWITCH = "Switch";
	//温度 空气检测仪
	public static final String TEMPERATURE = "temperature";
	/** 开关Button */
	private LinearLayout on_off_button_ll;
	private Button btn_light_onoff;

	/**
	 * 环境监测UI
	 */
	private LinearLayout air_controller;
	private TextView temperature_data_tv;
	private TextView air_humidity_data_tv;
	private TextView pm25_data_tv;
	private TextView formaldehyde_concentration_data_tv;
	private Button air_condition_btn_light_onoff;
	private Button coldBtn;
	private Button hotBtn;
	private Button less_wetBtn;
	private EditText air_condition_set_ed;
	private Button air_clean_btn_onoff;

	/**
	 * 照明控制UI
	 */
	private LinearLayout light_controller;
	private Button livingroom_light_onoff;
	private Button bedroom_light_onoff;
	private Button study_light_onoff;
	private Button porch_light_onoff;
	private Switch living_room_curtain_onoff;
	private Switch bedroom_curtain_onoff;
	private Switch study_curtain_onoff;

	/**
	 * 扫地机器人
	 */
	private LinearLayout house_clean_controller;
	private TextView electric_quantity_data_tv;
	private TextView sweep_progress_data_tv;
	private RelativeLayout sweep_progress_rl;
	private TextView electric_quantity_tv;

	/**
	 * 家庭影院
	 */
	private LinearLayout media_controller;
	private EditText volume_data_tv;
	private EditText brightness_data_tv;
	private Switch hifi_onoff;
	private Switch surround_onoff;
	private Switch threed_onoff;

	/**
	 * 咖啡机
	 */
	private LinearLayout coffee_controller;
	private TextView coffee_been_1_tv;
	private TextView coffee_been_2_tv;
	private TextView milk_1_tv;
	private TextView milk_2_tv;

	/** 设备监听器 */
	private GizWifiDeviceListener deviceListener = new GizWifiDeviceListener() {
		// 接收数据回调
		public void didReceiveData(GizWifiErrorCode result, GizWifiDevice device,
								   ConcurrentHashMap<String, Object> dataMap, int sn) {
			// 已定义的设备数据点，有布尔、数值和枚举型数据
			if (dataMap.get("data") != null) {
				ConcurrentHashMap<String, Object> map = (ConcurrentHashMap<String, Object>) dataMap.get("data");
				// 根据标识名，在回调的map中找到设备上报的值
				//空气检测仪
				if (map.get("aircondition") != null) {
					air_controller.setVisibility(View.VISIBLE);

					Boolean aircondition = (Boolean) map.get("aircondition");
					if (aircondition) {
						air_condition_btn_light_onoff.setSelected(true);
					} else {
						air_condition_btn_light_onoff.setSelected(false);
					}

					Integer temperature = (Integer) map.get(TEMPERATURE);
					String temperatureStr = String.valueOf(temperature);
					temperature_data_tv.setText(temperatureStr);
					if (temperature >= 30) {
						temperature_data_tv.setTextColor(getColor(R.color.tomato));
					} else {
						temperature_data_tv.setTextColor(getColor(R.color.text_blue));
					}

					Integer wet = (Integer) map.get("wet");
					String wetStr = String.valueOf(wet);
					air_humidity_data_tv.setText(wetStr + "%");
					if (wet >= 80) {
						air_humidity_data_tv.setTextColor(getColor(R.color.text_blue));
					} else {
						air_humidity_data_tv.setTextColor(getColor(R.color.black));
					}

					Integer pm25 = (Integer) map.get("pm25");
					String pm25Str = String.valueOf(pm25);
					pm25_data_tv.setText(pm25Str + "%");
					if (pm25 >= 80 && pm25 <= 200) {
						pm25_data_tv.setTextColor(getColor(R.color.text_blue));
					} else if (pm25 > 200){
						pm25_data_tv.setTextColor(getColor(R.color.tomato));
					} else {
						pm25_data_tv.setTextColor(getColor(R.color.black));
					}

					Integer formaldehyde = (Integer) map.get("formaldehyde");
					String formaldehydeStr = String.valueOf(formaldehyde);
					formaldehyde_concentration_data_tv.setText(formaldehydeStr + "%");
					if (formaldehyde >= 1 && pm25 <= 10) {
						formaldehyde_concentration_data_tv.setTextColor(getColor(R.color.text_blue));
					} else if (pm25 > 10){
						formaldehyde_concentration_data_tv.setTextColor(getColor(R.color.tomato));
					} else {
						formaldehyde_concentration_data_tv.setTextColor(getColor(R.color.black));
					}

					Boolean cold = (Boolean) map.get("cold");
					if (cold) {
						coldBtn.setSelected(true);
					} else {
						coldBtn.setSelected(false);
					}

					Boolean hot = (Boolean) map.get("hot");
					if (hot) {
						hotBtn.setSelected(true);
					} else {
						hotBtn.setSelected(false);
					}

					Boolean lesswet = (Boolean) map.get("lesswet");
					if (lesswet) {
						less_wetBtn.setSelected(true);
					} else {
						less_wetBtn.setSelected(false);
					}

					Boolean cleanair = (Boolean) map.get("cleanair");
					if (cleanair) {
						air_clean_btn_onoff.setSelected(true);
					} else {
						air_clean_btn_onoff.setSelected(false);
					}
					return;
				}

				//开关
				if (map.get(SWITCH) != null) {
					on_off_button_ll.setVisibility(View.VISIBLE);
					boolean status = (Boolean) map.get(SWITCH);
					// 根据设备上报的值更改按钮的图标
					btn_light_onoff.setSelected(status);
				}

				//照明控制
				if (map.get("livingroom") != null) {
					light_controller.setVisibility(View.VISIBLE);
					boolean livingroom = (Boolean) map.get("livingroom");
					boolean bedroom = (Boolean) map.get("bedroom");
					boolean study = (Boolean) map.get("study");
					boolean porch = (Boolean) map.get("porch");
					boolean livingroomcurtain = (Boolean) map.get("livingroomcurtain");
					boolean bedroomcurtain = (Boolean) map.get("bedroomcurtain");
					boolean studycurtain = (Boolean) map.get("studycurtain");
					livingroom_light_onoff.setSelected(livingroom);
					bedroom_light_onoff.setSelected(bedroom);
					study_light_onoff.setSelected(study);
					porch_light_onoff.setSelected(porch);
					living_room_curtain_onoff.setChecked(livingroomcurtain);
					bedroom_curtain_onoff.setChecked(bedroomcurtain);
					study_curtain_onoff.setChecked(studycurtain);
				}

				if (map.get("electricquantity") != null || map.get("heet") != null) {
					house_clean_controller.setVisibility(View.VISIBLE);
					if (map.get("electricquantity") != null) {
						Integer electricquantity = (Integer) map.get("electricquantity");
						String electricquantityStr = String.valueOf(electricquantity);
						electric_quantity_data_tv.setText(electricquantityStr + "%");
						if (electricquantity >= 30) {
							electric_quantity_data_tv.setTextColor(getColor(R.color.value_green));
						} else {
							electric_quantity_data_tv.setTextColor(getColor(R.color.tomato));
						}
					}

					if (map.get("heet") != null) {
						btn_light_onoff.setBackground(getDrawable(R.drawable.btn_fire_onoff_selector));
						electric_quantity_tv.setText("开水温度");
						Integer heet = (Integer) map.get("heet");
						String heetStr = String.valueOf(heet);
						electric_quantity_data_tv.setText(heetStr + "摄氏度");
						if (heet >= 60) {
							electric_quantity_data_tv.setTextColor(getColor(R.color.tomato));
						}else if (heet >= 30) {
							electric_quantity_data_tv.setTextColor(getColor(R.color.orange));
						} else {
							electric_quantity_data_tv.setTextColor(getColor(R.color.text_blue));
						}
					}

					if (map.get("sweepprogress") != null) {
						sweep_progress_rl.setVisibility(View.VISIBLE);
						Integer sweepprogress = (Integer) map.get("sweepprogress");
						String sweepprogressStr = String.valueOf(sweepprogress);
						sweep_progress_data_tv.setText(sweepprogressStr + "%");
					} else {
						sweep_progress_rl.setVisibility(View.GONE);
					}
				}

				if (map.get("volume") != null) {
					media_controller.setVisibility(View.VISIBLE);
					LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btn_light_onoff.getLayoutParams();
					layoutParams.height = 300;
					layoutParams.width = 300;
					btn_light_onoff.setLayoutParams(layoutParams);
					Integer volume = (Integer) map.get("volume");
					String volumeStr = String.valueOf(volume);
					volume_data_tv.setText(volumeStr);
					Integer brightness = (Integer) map.get("brightness");
					String brightnessStr = String.valueOf(brightness);
					brightness_data_tv.setText(brightnessStr);
					boolean hifi = (Boolean) map.get("hifi");
					boolean surround = (Boolean) map.get("surround");
					boolean threed = (Boolean) map.get("threed");
					living_room_curtain_onoff.setChecked(hifi);
					bedroom_curtain_onoff.setChecked(surround);
					study_curtain_onoff.setChecked(threed);
				}

				if (map.get("milk") != null) {
					coffee_controller.setVisibility(View.VISIBLE);
				}
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gos_device_control);
		initDevice();
		// 设置ActionBar
		setActionBar(true, true, device.getProductName());
		initView();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// 退出控制页面，取消设备订阅
		device.setSubscribe(false);
	}

	/**
	 * Description:初始化控件
	 */
	private void initView() {
		on_off_button_ll = (LinearLayout) findViewById(R.id.on_off_button_ll) ;
		btn_light_onoff = (Button) findViewById(R.id.btn_light_onoff);
		air_controller = (LinearLayout) findViewById(R.id.air_controller);
		temperature_data_tv = (TextView) findViewById(R.id.temperature_data_tv);
		air_humidity_data_tv = (TextView) findViewById(R.id.air_humidity_data_tv);
		pm25_data_tv = (TextView) findViewById(R.id.pm25_data_tv);
		formaldehyde_concentration_data_tv = (TextView) findViewById(R.id.formaldehyde_concentration_data_tv);
		air_condition_btn_light_onoff = (Button) findViewById(R.id.air_condition_btn_light_onoff);
		coldBtn = (Button) findViewById(R.id.cold);
		hotBtn = (Button) findViewById(R.id.hot);
		less_wetBtn = (Button) findViewById(R.id.less_wet);
		air_clean_btn_onoff = (Button) findViewById(R.id.air_clean_btn_onoff);
		air_condition_set_ed = (EditText) findViewById(R.id.air_condition_set_ed);

		light_controller = (LinearLayout) findViewById(R.id.light_controller);
		livingroom_light_onoff = (Button) findViewById(R.id.living_room_light_onoff);
		bedroom_light_onoff = (Button) findViewById(R.id.bedroom_light_onoff);
		study_light_onoff = (Button) findViewById(R.id.study_light_onoff);
		porch_light_onoff = (Button) findViewById(R.id.porch_light_onoff);
		living_room_curtain_onoff = (Switch) findViewById(R.id.living_room_curtain_onoff);
		bedroom_curtain_onoff = (Switch) findViewById(R.id.bedroom_curtain_onoff);
		study_curtain_onoff = (Switch) findViewById(R.id.study_curtain_onoff);

		house_clean_controller = (LinearLayout) findViewById(R.id.house_clean_controller);
		electric_quantity_data_tv = (TextView) findViewById(R.id.electric_quantity_data_tv);
		sweep_progress_data_tv = (TextView) findViewById(R.id.sweep_progress_data_tv);
		sweep_progress_rl = (RelativeLayout) findViewById(R.id.sweep_progress_rl);
		electric_quantity_tv = (TextView) findViewById(R.id.electric_quantity_tv);

		media_controller = (LinearLayout) findViewById(R.id.media_controller);
		volume_data_tv = (EditText) findViewById(R.id.volume_data_tv);
		brightness_data_tv = (EditText) findViewById(R.id.brightness_data_tv);
		hifi_onoff = (Switch) findViewById(R.id.hifi_onoff);
		surround_onoff = (Switch) findViewById(R.id.surround_onoff);
		threed_onoff = (Switch) findViewById(R.id.threed_onoff);

		coffee_controller = (LinearLayout) findViewById(R.id.coffee_controller);
		coffee_been_1_tv = (TextView) findViewById(R.id.coffee_been_1_tv);
		coffee_been_2_tv = (TextView) findViewById(R.id.coffee_been_2_tv);
		milk_1_tv = (TextView) findViewById(R.id.milk_1_tv);
		milk_2_tv = (TextView) findViewById(R.id.milk_2_tv);

		initListener();
	}

	private void initListener() {
		air_condition_set_ed.addTextChangedListener(new TextWatcher() {
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				if (!String.valueOf(s).isEmpty()) {
					try	{
						sendIntegerCommand("settemperature", Integer.valueOf(String.valueOf(s)));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		});



		btn_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (btn_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand(SWITCH, false);
					// 更改Button控件状态
					btn_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand(SWITCH, true);
					btn_light_onoff.setSelected(true);
				}
			}
		});

		initControllerListener();
	}

	private void initControllerListener() {
		air_condition_btn_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (air_condition_btn_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("aircondition", false);
					// 更改Button控件状态
					air_condition_btn_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand("aircondition", true);
					air_condition_btn_light_onoff.setSelected(true);
				}
			}
		});

		coldBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (coldBtn.isSelected()) {

				} else {
					setColdMode();
					coldBtn.setSelected(true);
					hotBtn.setSelected(false);
					less_wetBtn.setSelected(false);
				}
			}
		});

		hotBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (hotBtn.isSelected()) {

				} else {
					setHotMode();
					hotBtn.setSelected(true);
					coldBtn.setSelected(false);
					less_wetBtn.setSelected(false);
				}
			}
		});

		less_wetBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (less_wetBtn.isSelected()) {

				} else {
					setLessWetMode();
					less_wetBtn.setSelected(true);
					coldBtn.setSelected(false);
					hotBtn.setSelected(false);
				}
			}
		});

		air_clean_btn_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (air_clean_btn_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("cleanair", false);
					// 更改Button控件状态
					air_clean_btn_onoff.setSelected(false);
				} else {
					sendBooleanCommand("cleanair", true);
					air_clean_btn_onoff.setSelected(true);
				}
			}
		});



		livingroom_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (livingroom_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("livingroom", false);
					// 更改Button控件状态
					livingroom_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand("livingroom", true);
					livingroom_light_onoff.setSelected(true);
				}
			}
		});
		bedroom_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (bedroom_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("bedroom", false);
					// 更改Button控件状态
					bedroom_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand("bedroom", true);
					bedroom_light_onoff.setSelected(true);
				}
			}
		});
		study_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (study_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("study", false);
					// 更改Button控件状态
					study_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand("study", true);
					study_light_onoff.setSelected(true);
				}
			}
		});
		porch_light_onoff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (porch_light_onoff.isSelected()) {
					// 下发控制命令
					sendBooleanCommand("porch", false);
					// 更改Button控件状态
					porch_light_onoff.setSelected(false);
				} else {
					sendBooleanCommand("porch", true);
					porch_light_onoff.setSelected(true);
				}
			}
		});
		living_room_curtain_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("livingroomcurtain", true);
				} else {
					sendBooleanCommand("livingroomcurtain", false);
				}
			}
		});
		bedroom_curtain_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("bedroomcurtain", true);
				} else {
					sendBooleanCommand("bedroomcurtain", false);
				}
			}
		});
		study_curtain_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("studycurtain", true);
				} else {
					sendBooleanCommand("studycurtain", false);
				}
			}
		});

		volume_data_tv.addTextChangedListener(new TextWatcher() {
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				if (!String.valueOf(s).isEmpty()) {
					try	{
						sendIntegerCommand("volume", Integer.valueOf(String.valueOf(s)));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		});

		brightness_data_tv.addTextChangedListener(new TextWatcher() {
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				if (!String.valueOf(s).isEmpty()) {
					try	{
						sendIntegerCommand("brightness", Integer.valueOf(String.valueOf(s)));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		});

		hifi_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("hifi", true);
				} else {
					sendBooleanCommand("hifi", false);
				}
			}
		});
		surround_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("surround", true);
				} else {
					sendBooleanCommand("surround", false);
				}
			}
		});
		threed_onoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					sendBooleanCommand("threed", true);
				} else {
					sendBooleanCommand("threed", false);
				}
			}
		});

		coffee_been_1_tv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				coffee_been_1_tv.setSelected(true);
				coffee_been_2_tv.setSelected(false);
				sendBooleanCommand("coffee_bean", true);
			}
		});

		coffee_been_2_tv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				coffee_been_1_tv.setSelected(false);
				coffee_been_2_tv.setSelected(true);
				sendBooleanCommand("coffee_bean", false);
			}
		});

		milk_1_tv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				milk_1_tv.setSelected(true);
				milk_2_tv.setSelected(false);
				sendBooleanCommand("milk", true);
			}
		});

		milk_2_tv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				milk_1_tv.setSelected(false);
				milk_2_tv.setSelected(true);
				sendBooleanCommand("milk", false);
			}
		});
	}

	/**
	 * Description:初始化设备
	 */
	private void initDevice() {
		Intent intent = getIntent();
		device = (GizWifiDevice) intent.getParcelableExtra("GizWifiDevice");
		device.setListener(deviceListener);
		Log.i("Apptest", device.getDid());
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case android.R.id.home:
				this.finish();
				break;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * Description:下发命令方法
	 *
	 * @param onOff
	 *            true表示开灯，false表示关灯
	 */
	private void sendBooleanCommand(String key, boolean onOff) {
		int sn = 5;
		ConcurrentHashMap<String, Object> command = new ConcurrentHashMap<String, Object>();
		// map中key为云端创建数据点的标识名，value为需要传输的值
		command.put(key, onOff);
		// 调用write方法即可下发命令
		device.write(command, sn);
	}

	private void setColdMode() {
		int sn = 5;
		ConcurrentHashMap<String, Object> command = new ConcurrentHashMap<String, Object>();
		// map中key为云端创建数据点的标识名，value为需要传输的值
		command.put("cold", true);
		command.put("hot", false);
		command.put("lesswet", false);
		// 调用write方法即可下发命令
		device.write(command, sn);
	}

	private void setHotMode() {
		int sn = 5;
		ConcurrentHashMap<String, Object> command = new ConcurrentHashMap<String, Object>();
		// map中key为云端创建数据点的标识名，value为需要传输的值
		command.put("cold", false);
		command.put("hot", true);
		command.put("lesswet", false);
		// 调用write方法即可下发命令
		device.write(command, sn);
	}

	private void setLessWetMode() {
		int sn = 5;
		ConcurrentHashMap<String, Object> command = new ConcurrentHashMap<String, Object>();
		// map中key为云端创建数据点的标识名，value为需要传输的值
		command.put("cold", false);
		command.put("hot", false);
		command.put("lesswet", true);
		// 调用write方法即可下发命令
		device.write(command, sn);
	}

	private void sendIntegerCommand(String key, Integer value) {
		int sn = 5;
		ConcurrentHashMap<String, Object> command = new ConcurrentHashMap<String, Object>();
		// map中key为云端创建数据点的标识名，value为需要传输的值
		command.put(key, value);
		// 调用write方法即可下发命令
		device.write(command, sn);
	}
}
